﻿/*----------------------------------------------------------------
//  <copyright file="ModuleBase.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2024-02-01 13:34</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Authorization.Entities
{
    #region "模块信息基类"
    /// <summary>
    /// 模块信息基类
    /// </summary>
    [EventEntityIgnore]
    public abstract class ModuleBase<TModuleKey> : EntityBase<TModuleKey>, ICreatedTime
        where TModuleKey : struct, IEquatable<TModuleKey>
    {
        #region "属性"
        #region "获取或设置 模块编码"
        private string _Code = "";
        /// <summary>
        /// 获取或设置 模块编码
        /// </summary>
        [Column("Code")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Code)]
        [DisplayName("模块编码")]
        public string Code { get { return _Code; } set { _Code = value.ReplaceNull(); } }
        #endregion
        #region "获取或设置 模块名称"
        private string _Name = "";
        /// <summary>
        /// 获取或设置 模块名称
        /// </summary>
        [Column("Name")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("模块名称")]
        public string Name { get { return _Name; } set { _Name = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 模块完整编码"
        private string _FullCode = "";
        /// <summary>
        /// 获取或设置 模块完整编码
        /// </summary>
        [Column("FullCode")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("模块完整编码")]
        public string FullCode { get { return _FullCode; } set { _FullCode = value.ReplaceNull(); } }
        #endregion
        #region "获取或设置 模块完整名称"
        private string _FullName = "";
        /// <summary>
        /// 获取或设置 模块完整名称
        /// </summary>
        [Column("FullName")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.General)]
        [DisplayName("模块完整名称")]
        public string FullName { get { return _FullName; } set { _FullName = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 备注"
        private string _Remark = "";
        /// <summary>
        /// 获取或设置 备注
        /// </summary>
        [Column("Remark")]
        [StringSize(StringSizeType.Description)]
        [DisplayName("模块描述")]
        public string Remark { get { return _Remark; } set { _Remark = value.ReplaceNull(); } }
        #endregion

        #region "获取或设置 顺序编号"
        /// <summary>
        /// 获取或设置 顺序编号
        /// </summary>
        [Column("OrderNo")]
        [DisplayName("顺序编号")]
        public decimal OrderNo { get; set; }
        #endregion
        #region "获取或设置 节点树形路径"
        private string _TreePathString = "";
        /// <summary>
        /// 获取或设置 节点树形路径
        /// <para>树链Id根据一定格式构建的字符串，形如："$1$,$3$,$4$,$7$"，编辑时更新。</para>
        /// </summary>
        [Column("TreePathString")]
        [StringSize(StringSizeType.Description)]
        [DisplayName("节点树形路径")]
        public string TreePathString { get { return _TreePathString; } set { _TreePathString = value.ReplaceNull(); } }
        #endregion
        #region "获取或设置 父模块编号"
        /// <summary>
        /// 获取或设置 父模块编号
        /// </summary>
        [Column("ParentId")]
        [DisplayName("父模块编号")]
        public TModuleKey? ParentId { get; set; }
        #endregion

        #region "获取或设置 创建时间 ICreatedTime、ICreationAudited  可装载接口，在数据创建时可自动设置当前时间"
        /// <summary>
        /// 获取或设置 创建时间
        /// </summary>
        [Column("CreatedTime")]
        [DisplayName("创建时间")]
        public DateTime CreatedTime { get; set; }
        #endregion

        #region "获取 从根结点到当前结点的树形路径编号数组"
        /// <summary>
        /// 获取 从根结点到当前结点的树形路径编号数组，
        /// 由<see cref="TreePathString"/>属性转换，此属性仅支持在内存中使用
        /// </summary>
        [NotMapped]
        public TModuleKey[] TreePathIds
        {
            get
            {
                return TreePathString?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(m => m.Trim('$').CastTo<TModuleKey>()).ToArray() ?? Array.Empty<TModuleKey>();
            }
        }
        #endregion

        #endregion

    }
    #endregion

}
